package sisi.invoices;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.event.CreateEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zk.ui.util.ConventionWires;
import org.zkoss.zul.Bandbox;
import org.zkoss.zul.Doublebox;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.Label;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

import sisi.General;
import sisi.enquires.Reqshipfuelass;
import sisi.enquires.ReqshipfuelassController;
import sisi.ports.Port;
import sisi.ports.PortController;
import sisi.products.Product;
import sisi.products.ProductsController;


/**
 * DayBookWindow.java - Controller class for <i>DayBook window</i>. 
 * @author Pedro Gonzalez pedro@sisisoftware.it
 * @author SISI Software - www.sisisoftware.it
 * @version 1.0, 25/2/2015
 * 
 */


@SuppressWarnings({ "rawtypes", "unchecked", "serial" })
public class DayBookWindow extends Window implements 
				org.zkoss.zk.ui.ext.AfterCompose {
//window
private Window windowDayBook;
private Listbox boxEnqNumber, boxCustInvoices, boxSuppInvoices;
private Bandbox bbEnqNumber;
private Intbox ibRef;
private Textbox tbCustomer, tbPort, tbCountry;
private Doublebox dbClActTaxed, dbClActVAT, dbClActTotal, dbClPasTaxed, dbClPasVAT, dbClPasTotal, dbClProfit, dbClProfitPerc;
private Doublebox dbPdActTaxed, dbPdActVAT, dbPdActTotal, dbPdPasTaxed, dbPdPasVAT, dbPdPasTotal, dbPdProfit, dbPdProfitPerc;
private Doublebox dbEpAct, dbEpPas, dbEpDelta;
private Doublebox dbTotalRequestedUSD, dbDeltaRequestedUSD, dbDeltaRequestedPercUSD, dbTotalPaidUSD, dbDeltaPaidUSD, dbDeltaPaidPercUSD;
private Doublebox dbTotalRequestedEUR, dbDeltaRequestedEUR, dbDeltaRequestedPercEUR, dbTotalPaidEUR, dbDeltaPaidEUR, dbDeltaPaidPercEUR;
private Doublebox dbTotalRequestedGBP, dbDeltaRequestedGBP, dbDeltaRequestedPercGBP, dbTotalPaidGBP, dbDeltaPaidGBP, dbDeltaPaidPercGBP;
private Doublebox dbTotalRequestedMXN, dbDeltaRequestedMXN, dbDeltaRequestedPercMXN, dbTotalPaidMXN, dbDeltaPaidMXN, dbDeltaPaidPercMXN;
private Doublebox dbPTotalRequestedUSD, dbPTotalPaidUSD, dbPTotalRequestedEUR, dbPTotalPaidEUR;
private Doublebox dbPTotalRequestedGBP, dbPTotalPaidGBP, dbPTotalRequestedMXN, dbPTotalPaidMXN;

private Reqshipfuelass req;
private boolean clicked = false;

protected Map<String, Object> args;

		public void onCreate$windowDayBook(Event event) {

		CreateEvent ce = (CreateEvent) ((ForwardEvent) event).getOrigin();
		args = (Map<String, Object>) ce.getArg();

		
		ListModelList listModelListEnqNumber = new ListModelList();
		listModelListEnqNumber.addAll(new ReqshipfuelassController().getList(null));
		boxEnqNumber.setModel(listModelListEnqNumber);
		boxEnqNumber.setItemRenderer(new EnqNumberRenderer());
		bbEnqNumber.setReadonly(false);

		//finestraDettaglio.setVisible(false);
		//bbEnqNumber.setReadonly(true);		
		//Component tmp = finestraDettaglio.getFellow("boxDetail");
		//boxDetail = (Listbox) tmp; 
				
		}

		
	public void afterCompose() {

		// wire variables
		ConventionWires.wireVariables(this, this);

		// auto forward
		ConventionWires.addForwards(this, this);
	}

	
	public void onSelect$boxEnqNumber(Event event){
		int iSelected = boxEnqNumber.getSelectedIndex();
		if (iSelected == -1){
			return;
		}
		
		Reqshipfuelass req = (Reqshipfuelass)boxEnqNumber.getItemAtIndex(iSelected).getAttribute("rigaEnqNumber");
		
		//Object oEnqNumber = boxEnqNumber.getItemAtIndex(iSelected).getAttribute("rigaEnqNumber");
		//Object[] oRiga = (Object[])oEnqNumber;
		//Integer id = (Integer)oRiga[0];
		ibRef.setValue(req.getId());
		bbEnqNumber.setValue(""+req.getId());
		changeORokEnqNumber(null);

		//finestraDettaglio.setVisible(true);
		//viewDettaglio(id);
	}
	
	
	public void onOK$bbEnqNumber(Event event){
		changeORokEnqNumber(event);
	}
	
	public void onChange$bbEnqNumber(Event event){
		changeORokEnqNumber(event); 
	}
	
	private void changeORokEnqNumber(Event event){
		
		if (bbEnqNumber.getValue()==null){
			return;
		}
	
		boolean valido = false;
		req = new ReqshipfuelassController().getxId(Integer.valueOf( bbEnqNumber.getValue() ) );
		if (req.getId()!=null && req.getId().compareTo(Integer.valueOf( bbEnqNumber.getValue() ))==0){
			valido = true;
		}

		if (!valido){
			Messagebox.show("Enquire number not valid! - "+bbEnqNumber.getValue(), "Information", Messagebox.OK, Messagebox.INFORMATION);
			bbEnqNumber.setValue(null);			
		} else {
			//finestraDettaglio.setVisible(true);
			
			ibRef.setValue(Integer.valueOf( bbEnqNumber.getValue() ));
			viewDettaglio();
		}
	}
		
	private void viewDettaglio(){
		
		ibRef.setValue(req.getId());
		tbCustomer.setValue(req.getVesselname());
		tbPort.setValue(req.getPorttoref());
		
		Port port = new PortController().getPortxId(req.getIdportref());
		String country = General.trimNull( port.getCountry() );
		tbCountry.setValue(country);
		
		dbClActTaxed.setValue( new CustinvoiceController().BrogliaccioSum( req.getId(), 1 ) );
		dbClActVAT.setValue( new CustinvoiceController().getSommaGeneratedQuery("SELECT SUM(c.totalvat) FROM Custinvoice c WHERE c.order="+req.getId()+" AND UPPER( c.stat ) <> 'HI' "));
		dbClActTotal.setValue( dbClActTaxed.getValue() + dbClActVAT.getValue() );
		
		dbClPasTaxed.setValue( new CustinvoiceController().BrogliaccioSum( req.getId(), 2 ) );
		dbClPasVAT.setValue( new CustinvoiceController().getSommaGeneratedQuery("SELECT SUM(c.totvat) FROM Suppinvoice c WHERE c.order="+req.getId()+" AND UPPER( c.stat ) <> 'HI' "));
		dbClPasTotal.setValue( dbClPasTaxed.getValue() + dbClPasVAT.getValue() ); 
		
		dbClProfit.setValue( dbClActTaxed.getValue() - dbClPasTaxed.getValue() );
		Double percClProfit = 0.00;
		if (dbClActTaxed.getValue().compareTo( new Double(0) ) != 0 && dbClPasTaxed.getValue().compareTo( new Double(0) ) != 0  ){
			percClProfit = ( ( dbClActTaxed.getValue() / dbClPasTaxed.getValue() ) * 100 ) - 100;
		}
		dbClProfitPerc.setValue(percClProfit);
		
		dbPdActTaxed.setValue( new CustinvoiceController().BrogliaccioSum( req.getId(), 3 ) );
		dbPdActVAT.setValue( new CustinvoiceController().getSommaGeneratedQuery("SELECT SUM(c.totalvat) FROM Custinvoice c WHERE c.order="+req.getId()+" AND UPPER( c.stat ) = 'PD' "));
		dbPdActTotal.setValue( dbPdActTaxed.getValue() + dbPdActVAT.getValue() );		
		
		dbPdPasTaxed.setValue( new CustinvoiceController().BrogliaccioSum( req.getId(), 4 ) );
		dbPdPasVAT.setValue( new CustinvoiceController().getSommaGeneratedQuery("SELECT SUM(c.totvat) FROM Suppinvoice c WHERE c.order="+req.getId()+" AND UPPER( c.stat ) = 'PD' "));
		dbPdPasTotal.setValue( dbPdPasTaxed.getValue() + dbPdPasVAT.getValue() );
		
		dbPdProfit.setValue( dbPdActTaxed.getValue() - dbPdPasTaxed.getValue() );
		Double percPdProfit = 0.00;
		if (dbPdActTaxed.getValue().compareTo( new Double(0) ) != 0 && dbPdPasTaxed.getValue().compareTo( new Double(0) ) != 0  ){
			percPdProfit = ( ( dbPdActTaxed.getValue() / dbPdPasTaxed.getValue() ) * 100 ) - 100;
		}
		dbPdProfitPerc.setValue(percPdProfit);
		
		dbEpAct.setValue(dbPdActTotal.getValue());
		dbEpPas.setValue(dbPdPasTotal.getValue());
		dbEpDelta.setValue(dbEpAct.getValue()-dbEpPas.getValue());
		
		
		// Receivable
		
		ListModelList lmlCustInvoices = new ListModelList();
		List<Custinvoice> ciList = new CustinvoiceController().getList(ibRef.getValue());
		lmlCustInvoices.addAll(ciList);
		boxCustInvoices.setModel(lmlCustInvoices);
		boxCustInvoices.setItemRenderer(new CustInvoicesRenderer());
		
		
		ListModelList lmlSuppInvoices = new ListModelList();
		List<Suppinvoice> siList = new SuppinvoiceController().getList(ibRef.getValue());
		lmlSuppInvoices.addAll(siList);
		boxSuppInvoices.setModel(lmlSuppInvoices);
		boxSuppInvoices.setItemRenderer(new SuppInvoicesRenderer());
		
		Double trU = 0.00, tpU = 0.00, trE = 0.00, tpE = 0.00, trG = 0.00, tpG = 0.00, trM = 0.00, tpM = 0.00;
		for (Custinvoice custinvoice : ciList) {
			if (custinvoice.getCurr().equalsIgnoreCase("USD")){
				trU += custinvoice.getTotaltaxedvat();
				tpU += custinvoice.getPaidamount();
			} else if (custinvoice.getCurr().equalsIgnoreCase("EUR")){
				trE += custinvoice.getTotaltaxedvat();
				tpE += custinvoice.getPaidamount();
			} else if (custinvoice.getCurr().equalsIgnoreCase("GBP")){
				trG += custinvoice.getTotaltaxedvat();
				tpG += custinvoice.getPaidamount();
			} else if (custinvoice.getCurr().equalsIgnoreCase("MXN")){
				trM += custinvoice.getTotaltaxedvat();
				tpM += custinvoice.getPaidamount();
			}
		}
		dbTotalRequestedUSD.setValue(trU);
		dbTotalPaidUSD.setValue(tpU);
		dbTotalRequestedEUR.setValue(trE);
		dbTotalPaidEUR.setValue(tpE);
		dbTotalRequestedGBP.setValue(trG);
		dbTotalPaidGBP.setValue(tpG);
		dbTotalRequestedMXN.setValue(trM);
		dbTotalPaidMXN.setValue(tpM);

		Double trU2 = 0.00, tpU2 = 0.00, trE2 = 0.00, tpE2 = 0.00, trG2 = 0.00, tpG2 = 0.00, trM2 = 0.00, tpM2 = 0.00;
		for (Suppinvoice suppinvoice : siList) {
			if (suppinvoice.getCurr().equalsIgnoreCase("USD")){
				trU2 += suppinvoice.getTotalinvoice();
				tpU2 += suppinvoice.getPaidamount();
			} else if (suppinvoice.getCurr().equalsIgnoreCase("EUR")){
				trE2 += suppinvoice.getTotalinvoice();
				tpE2 += suppinvoice.getPaidamount();
			} else if (suppinvoice.getCurr().equalsIgnoreCase("GBP")){
				trG2 += suppinvoice.getTotalinvoice();
				tpG2 += suppinvoice.getPaidamount();
			} else if (suppinvoice.getCurr().equalsIgnoreCase("MXN")){
				trM2 += suppinvoice.getTotalinvoice();
				tpM2 += suppinvoice.getPaidamount();
			}
		}
		dbPTotalRequestedUSD.setValue(trU2);
		dbPTotalPaidUSD.setValue(tpU2);
		dbPTotalRequestedEUR.setValue(trE2);
		dbPTotalPaidEUR.setValue(tpE2);
		dbPTotalRequestedGBP.setValue(trG2);
		dbPTotalPaidGBP.setValue(tpG2);
		dbPTotalRequestedMXN.setValue(trM2); 
		dbPTotalPaidMXN.setValue(tpM2);

		
		// DELTA
		
		// USD
		dbDeltaRequestedUSD.setValue(trU - trU2);
		dbDeltaRequestedPercUSD.setValue( (dbDeltaRequestedUSD.getValue().compareTo(Double.valueOf(0))==0 ? 0.00 :  dbDeltaRequestedUSD.getValue() / dbTotalRequestedUSD.getValue() ));

		dbDeltaPaidUSD.setValue(tpU - tpU2);
		dbDeltaPaidPercUSD.setValue( (dbDeltaPaidUSD.getValue().compareTo(Double.valueOf(0))==0 ? 0.00 : dbDeltaPaidUSD.getValue() / dbTotalPaidUSD.getValue() ));
		
		// EUR
		dbDeltaRequestedEUR.setValue(trE - trE2);
		dbDeltaRequestedPercEUR.setValue( (dbDeltaRequestedEUR.getValue().compareTo(Double.valueOf(0))==0 ? 0.00 :  dbDeltaRequestedEUR.getValue() / dbTotalRequestedEUR.getValue() ));

		dbDeltaPaidEUR.setValue(tpE - tpE2);
		dbDeltaPaidPercEUR.setValue( (dbDeltaPaidEUR.getValue().compareTo(Double.valueOf(0))==0 ? 0.00 : dbDeltaPaidEUR.getValue() / dbTotalPaidEUR.getValue() ));

		// GBP
		dbDeltaRequestedGBP.setValue(trG - trG2);
		dbDeltaRequestedPercGBP.setValue( (dbDeltaRequestedGBP.getValue().compareTo(Double.valueOf(0))==0 ? 0.00 :  dbDeltaRequestedGBP.getValue() / dbTotalRequestedGBP.getValue() ));

		dbDeltaPaidGBP.setValue(tpG - tpG2);
		dbDeltaPaidPercGBP.setValue( (dbDeltaPaidGBP.getValue().compareTo(Double.valueOf(0))==0 ? 0.00 : dbDeltaPaidGBP.getValue() / dbTotalPaidGBP.getValue() ));

		// MXN
		dbDeltaRequestedMXN.setValue(trM - trM2);
		dbDeltaRequestedPercMXN.setValue( (dbDeltaRequestedMXN.getValue().compareTo(Double.valueOf(0))==0 ? 0.00 :  dbDeltaRequestedMXN.getValue() / dbTotalRequestedMXN.getValue() ));

		dbDeltaPaidMXN.setValue(tpM - tpM2);
		dbDeltaPaidPercMXN.setValue( (dbDeltaPaidMXN.getValue().compareTo(Double.valueOf(0))==0 ? 0.00 : dbDeltaPaidMXN.getValue() / dbTotalPaidMXN.getValue() ));

		
	}
	
	

	

	private class EnqNumberRenderer implements ListitemRenderer {

		@Override
		public void render(Listitem item, Object data, int index)
				throws Exception {
			
			Reqshipfuelass reqshipfuelass = (Reqshipfuelass)data;
			Port port = new PortController().getPortxId(reqshipfuelass.getIdportref());
			String country = General.trimNull( port.getCountry() );
			
			new Listcell(""+reqshipfuelass.getId()).setParent(item);
			new Listcell(""+reqshipfuelass.getVesselname()).setParent(item);
			new Listcell(""+reqshipfuelass.getPorttoref()).setParent(item);
			new Listcell(""+country).setParent(item);
			item.setAttribute("rigaEnqNumber", data);
		}
	}


	private class CustInvoicesRenderer implements ListitemRenderer {

		@Override
		public void render(Listitem item, Object data, int index)
				throws Exception {
			
			Custinvoice ci = (Custinvoice)data;
			
			new Listcell(""+ci.getOrder()).setParent(item);
			//new Listcell(""+ci.getCustnuminvoice()).setParent(item);
			
			Label lblCustnuminvoice = new Label( ""+ci.getCustnuminvoice() );
			if (ci.getCustnuminvoice()!=null && ci.getCustnuminvoice()!=0){
				lblCustnuminvoice.setStyle("color: red; background: yellow");
				
				lblCustnuminvoice.addEventListener("onClick", new EventListener() {
					public void onEvent(Event event) {
						Component componente = event.getTarget();
						
						if (clicked){
							return;
						}
						clicked = true;
						
						Integer iIndex = ((Listitem)componente.getParent().getParent()).getIndex();
						Object oRiga = boxCustInvoices.getItemAtIndex(iIndex).getAttribute("rigaCustInvoice");
						Custinvoice ci = (Custinvoice)oRiga;
						
						HashMap map = new HashMap();
						map.put("lNuovo", true);

						map.put("ci", ci);
						map.put("si", null );
						map.put("seleziona", false);
						map.put("valore", 1);
							
						Window finestraInvoices = (Window) Executions.createComponents("/invoices/invoices.zul", null, map);
						finestraInvoices.doModal();
						
						clicked = false;

					}
					});
				
			}
			
			Listcell lcNumInvoice = new Listcell();
			lcNumInvoice.appendChild(lblCustnuminvoice);
			lcNumInvoice.setParent(item);
			
			
			new Listcell(""+General.formatoFecha( ci.getInvoicedt() ) ).setParent(item);
			new Listcell(""+General.formatoFecha( ci.getDuedate() ) ).setParent(item);
			
			Label lblStatus = new Label( ci.getStat() );
			if (ci.getStat().equalsIgnoreCase("PD")){
				lblStatus.setStyle("color: red; background: yellow");
				
				lblStatus.addEventListener("onClick", new EventListener() {
					public void onEvent(Event event) {
						Component componente = event.getTarget();
						
						if (clicked){
							return;
						}
						clicked = true;
						
						Integer iIndex = ((Listitem)componente.getParent().getParent()).getIndex();
						Object oRiga = boxCustInvoices.getItemAtIndex(iIndex).getAttribute("rigaCustInvoice");
						Custinvoice ci = (Custinvoice)oRiga;
						
						HashMap map = new HashMap();
						map.put("lNuovo", true);
							
						String docType = "";
						String ref = "";
						String invref = "";
						Integer idInvoiceRecNum = 0;

						docType = "A";
						ref = ""+ci.getOrder();
						invref = ""+ci.getCustnuminvoice();
						idInvoiceRecNum = ci.getRecnum();
						if (ci.getType().equalsIgnoreCase("C") || ci.getType().equalsIgnoreCase("D") ){
							docType = "C";		
						}
							
						map.put("docType", docType);
						map.put("ref", ref);
						map.put("invref", invref);
						map.put("idInvoiceRecNum", idInvoiceRecNum); 
						map.put("valoreOpzioneMenu", 1 );
						map.put("ci", ci);
						map.put("si", (new Suppinvoice()) );
							
						Window finestraEditCash = (Window) Executions.createComponents("/editCash.zul", null, map);
						finestraEditCash.doModal();
						
						clicked = false;

					}
					});
				
			}
			
			Listcell lc = new Listcell();
			lc.appendChild(lblStatus);
			lc.setParent(item);
			


			new Listcell(""+ci.getType()).setParent(item);
			new Listcell(""+ci.getCurr()).setParent(item);
			new Listcell(""+General.decimalFormat("###,###,##0.00", ci.getTotaltaxedvat())).setParent(item);
			new Listcell(""+General.decimalFormat("###,###,##0.00", ci.getPaidamount() ) ).setParent(item);
			
			Double delta = General.doubleZeroNull( ci.getTotaltaxedvat() - ci.getPaidamount() );
			
			new Listcell(""+General.decimalFormat("###,###,##0.00", delta ) ).setParent(item);
			new Listcell(""+ ( ci.getBankdoc()!=null ? ci.getBankdoc() : "" )).setParent(item);
			new Listcell(""+General.formatoFecha( ci.getBankdtdoc() ) ).setParent(item);
			item.setAttribute("rigaCustInvoice", data); 
		}
	}

	
	private class SuppInvoicesRenderer implements ListitemRenderer {

		@Override
		public void render(Listitem item, Object data, int index)
				throws Exception {
			
			Suppinvoice si = (Suppinvoice)data;
			
			new Listcell(""+si.getOrder()).setParent(item);
			//new Listcell(""+si.getSuppnuminvoice()).setParent(item);
			Label lblSuppnuminvoice = new Label( ""+si.getSuppnuminvoice() );
			if (si.getSuppnuminvoice()!=null && !si.getSuppnuminvoice().isEmpty()){
				lblSuppnuminvoice.setStyle("color: red; background: yellow");
				
				lblSuppnuminvoice.addEventListener("onClick", new EventListener() {
					public void onEvent(Event event) {
						Component componente = event.getTarget();
						
						if (clicked){
							return;
						}
						clicked = true;
						
						Integer iIndex = ((Listitem)componente.getParent().getParent()).getIndex();
						Object oRiga = boxSuppInvoices.getItemAtIndex(iIndex).getAttribute("rigaSuppInvoice");
						Suppinvoice si = (Suppinvoice)oRiga;
						
						HashMap map = new HashMap();
						map.put("lNuovo", true);

						map.put("ci", null );
						map.put("si", si );
						map.put("seleziona", false);
						map.put("valore", 5);
							
						Window finestraInvoices = (Window) Executions.createComponents("/invoices/invoices.zul", null, map);
						finestraInvoices.doModal();
						
						clicked = false;

					}
					});
				
			}
			
			Listcell lcNumInvoice = new Listcell();
			lcNumInvoice.appendChild(lblSuppnuminvoice);
			lcNumInvoice.setParent(item);
			
			
			new Listcell(""+General.formatoFecha( si.getInvoicedt() ) ).setParent(item);
			new Listcell(""+si.getSuppname() ).setParent(item);
			new Listcell(""+General.formatoFecha( si.getDuedate() ) ).setParent(item);
			
			
			Label lblStatus = new Label( si.getStat() );
			if (si.getStat().equalsIgnoreCase("PD")){
				lblStatus.setStyle("color: red; background: yellow");
							
				lblStatus.addEventListener("onClick", new EventListener() {
					public void onEvent(Event event) {
						
						Component componente = event.getTarget();
						if (clicked){
							return;
						}
						clicked = true;
						
						Integer iIndex = ((Listitem)componente.getParent().getParent()).getIndex();
						Object oRiga = boxSuppInvoices.getItemAtIndex(iIndex).getAttribute("rigaSuppInvoice");
						Suppinvoice si = (Suppinvoice)oRiga;
						
						HashMap map = new HashMap();
						map.put("lNuovo", true);
							
						String docType = "";
						String ref = ""; 
						String invref = "";
						Integer idInvoiceRecNum = 0;

						docType = "P";
						ref = ""+si.getOrder();
						invref = ""+si.getSuppnuminvoice();
						idInvoiceRecNum = si.getRecnum();
						if (si.getType().equalsIgnoreCase("D") ){
							docType = "D";		
						}
							
						map.put("docType", docType);
						map.put("ref", ref);
						map.put("invref", invref);
						map.put("idInvoiceRecNum", idInvoiceRecNum);
						map.put("valoreOpzioneMenu", 1 );
						map.put("ci", new Custinvoice() );
						map.put("si", si );
							
						Window finestraEditCash = (Window) Executions.createComponents("/editCash.zul", null, map);
						finestraEditCash.doModal();
						
						clicked = false;

					}
					});
				
			}

			
			Listcell lc = new Listcell();
			lc.appendChild(lblStatus);
			lc.setParent(item);	
			
			new Listcell(""+si.getType()).setParent(item);
			new Listcell(""+si.getCurr()).setParent(item);
			new Listcell(""+General.decimalFormat("###,###,##0.00", si.getTotalinvoice() ) ).setParent(item);
			new Listcell(""+General.decimalFormat("###,###,##0.00", si.getPaidamount() ) ).setParent(item);
			
			Double delta = General.doubleZeroNull( si.getTotalinvoice() - si.getPaidamount() );
			
			new Listcell(""+General.decimalFormat("###,###,##0.00", delta ) ).setParent(item);
			new Listcell(""+ ( si.getBankdoc()!=null ? si.getBankdoc() : "" )).setParent(item);
			new Listcell(""+General.formatoFecha( si.getBankdtdoc() ) ).setParent(item);
			item.setAttribute("rigaSuppInvoice", data); 
		}
	}
	
	
}
